﻿@{
    ViewData["Title"] = "合并科室维护";
}
<div class="layui-fluid">
    <form class="layui-card layui-form" lay-filter="layuiadmin-form-list" id="dtFrm" style="padding: 20px 30px 0 0;">
        <div class="layui-card-body">
            @*<div class="layui-form-item">
                <label for="DictType" class="layui-form-label">
                    <span class="x-red">*</span>科室代码
                </label>
                <div class="layui-input-block">
                    <input type="text" id="DeptCode" name="DeptCode" value="@Model.DeptCode" verify="required" autocomplete="off" class="layui-input">
                </div>
            </div>*@
            <div class="layui-form-item">
                <label for="Name" class="layui-form-label">
                    <span class="x-red">*</span>科室名称
                </label>
                <div class="layui-input-block">
                    <input type="text" id="DeptName" name="DeptName" value="@Model.DeptName" verify="required" autocomplete="off" class="layui-input">
                    <input type="hidden" id="DeptCode" name="DeptCode" value="@Model.DeptCode" />
                </div>
            </div>
            <div class="layui-form-item">
                <label for="Code" class="layui-form-label">
                    <span class="x-red">*</span>拼音码
                </label>
                <div class="layui-input-block">
                    <input type="text" id="SpellCode" name="SpellCode" required="" value="@Model.SpellCode" verify="required" autocomplete="off" class="layui-input">
                </div>
            </div>
            @*<div class="layui-form-item">
                <label for="DeptType" class="layui-form-label">
                    <span class="x-red">*</span>科室类型
                </label>
                <div class="layui-input-block">
                    <select lay-filter="DeptType" id="DeptType" name="DeptType" lay-verify="required">
                        <option value="">--请选择类型--</option>
                        <option value="1">门诊</option>
                        <option value="2">住院</option>
                        <option value="3">其他</option>
                    </select>
                </div>
            </div>*@
            <div class="layui-form-item">
                <label for="SortNo" class="layui-form-label">
                    <span class="x-red">*</span>院区
                </label>
                <div class="layui-input-block">
                    <select lay-filter="HospitalArea" id="HospitalArea" name="HospitalArea" lay-verify="required">
                        <option value="">--请选择院区--</option>
                        <option value="00">全院</option>
                        <option value="01">老院</option>
                        <option value="02">新院</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="SortNo" class="layui-form-label">
                    <span class="x-red">*</span>是否有效
                </label>
                <div class="layui-input-block">
                    <select lay-filter="ValidFlag" id="ValidFlag" name="ValidFlag" lay-verify="required">
                        <option value="">--请选择院区--</option>
                        <option value="1">有效</option>
                        <option value="0">无效</option>
                    </select>
                </div>
            </div>
            <div id="btnContainer" class="layui-form-item" style="text-align:center;">
                <button class="layui-btn" type="button" onclick="doAdd()">
                    保存
                </button>
                <button class="layui-btn layui-btn-danger" type="button" onclick="onCancel()">
                    取消
                </button>
            </div>
        </div>
    </form>
</div>
<script type="text/javascript">
    var layer;
    var admin;
    layui.config({
        base: '/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['layer','index','form'], function () {
        var layer = layui.layer
            , $ = layui.$, form = layui.form;
        admin = layui.admin;
        admin.req({
            url: '/DeptMergeInfo/Get' //实际使用请改成服务端真实接口
            , method: 'get'
            , data: "deptCode=@Request["deptCode"]"
            , done: function (res) {
                initForm("dtFrm", res.data);
                form.render(null);
            }
        });

        $("#DeptName").blur(function () {
            admin.req({
                url: '/DeptMergeInfo/GetInitials' //实际使用请改成服务端真实接口
                , method: 'post'
                , data: "deptName="+$(this).val()
                , done: function (res) {
                    $("#SpellCode").val(res.data);
                }
            });
        });
    });

    function doAdd() {
        if (valid("#dtFrm") > 0) {
            layer.alert("红色显示项必填");
            return;
        }
        var data = $("#dtFrm").serialize();
         admin.req({
             url: '/DeptMergeInfo/Save' //实际使用请改成服务端真实接口
            , method: 'post'
            , data: data
             , done: function (res) {
                 layer.alert(res.msg, function () {
                     var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                     parent.layui.table.reload('LAY-dept-list'); //重载表格
                     parent.layer.close(index); //再执行关闭
                 });
            }
        });
    }

    function valid(fromid) {
        var not = 0;
        $(fromid).find("[verify='required']").each(function () {
            if ($(this).val() == "") {
                $(this).parent().parent().find("label").css("color", "red");
                not++;
            } else {
                $(this).parent().parent().find("label").css("color", "");
            }
        });
        return not;
    }

    function onCancel() {
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
    }
</script>
